#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-03-13 11:58:05

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options


define('port', default=8000, type=int, help='指定监听的端口')


class IndexHandler(tornado.web.RequestHandler):
    """ 请求处理类 """
    def get(self):
        greeting = self.get_argument('greeting', 'hello')
        self.write(greeting + ', test')


if __name__ == '__main__':
    # 解析命令行参数
    tornado.options.parse_command_line()
    # 构建app对象，用于处理对应的请求
    app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
    # 将app传入HTTP server 类中，创建一个HTTP server对象
    http_server = tornado.httpserver.HTTPServer(app)
    # 设置HTTP server相关的参数
    http_server.listen(options.port)
    # 启动tornado 服务
    tornado.ioloop.IOLoop.instance().start()
